<template>
	<view class="team">
		<view class="team_top">
			<view class="input">
				<u-search v-model="keyword" @search='searchBtn' height="64" :show-action="false" placeholder="请输入会员名称或手机号查询"></u-search>
			</view>
			<view class="nav">
				<u-tabs :list="navList" height='88' active-color='#26C281' inactive-color='#222222' :is-scroll="false" :current="current" @change="navChange"></u-tabs>
			</view>
		</view>
		<view style="height: 176rpx;"></view>
		<!--  -->
		<view class="num_list" v-if="current==0 && info">
			<view class="txt">
				<text class="t_num">{{info.team_num}}</text>
				<text class="t_tip">成员总数</text>
			</view>
			<view class="txt">
				<text class="t_num">{{info.fd_num}}</text>
				<text class="t_tip">副店长</text>
			</view>
			<view class="txt">
				<text class="t_num">{{info.gl_num}}</text>
				<text class="t_tip">管理员</text>
			</view>
			<view class="txt">
				<text class="t_num">{{info.dy_num}}</text>
				<text class="t_tip">店员</text>
			</view>
		</view>
		<view class="num_list" v-if="current==2 && info">
			<view class="txt">
				<text class="t_num">{{info.team_num}}</text>
				<text class="t_tip">成员总数</text>
			</view>
			<view class="txt">
				<text class="t_num">{{total}}</text>
				<text class="t_tip">直推会员</text>
			</view>
		</view>
		<!--  -->
		<view class="no_html" v-if="list.length==0">
			<image src="@/static/images/no_img5.png" mode=""></image>
			<text>暂无团队数据</text>
		</view>
		<!--  -->
		<view v-else>
			<view class="list" v-for="(item,index) in list" :key="index">
				<view class="list_top">
					<view class="left">
						<image :src="item.avatar || avtar" mode="aspectFill"></image>
						<text>{{item.username}} {{item.mobile}}</text>
						<text v-if="userinfo.id==item.one_id">直推</text>
						<text class="left_tip" v-if="item.status!=='normal'">已锁定</text>
					</view>
					<view class="right" v-if="item.level==2">管理</view>
					<view class="right" v-if="item.level==3">副店</view>
					<view class="right" v-if="item.level==4">店长</view>
				</view>
				<view class="text">
					<text class="left">直推人数</text>
					<text class="right">{{item.one_num}}</text>
				</view>
				<view class="text">
					<text class="left">注册时间</text>
					<text class="right">{{item.createtime}}</text>
				</view>
				<view class="text" v-if="item.tjr.username">
					<text class="left">推荐人</text>
					<text class="right">{{item.tjr.username}} {{item.tjr.mobile}}</text>
				</view>
				<view class="btn">
					<text @click="detailsBtn(item.id)">查看详情</text>
				</view>
			</view>
			<view class="mall_loading" v-if="list.length" style="padding-top: 24rpx;">
				<u-loadmore :status="status" color='#999' />
			</view>
		</view>
	</view>
</template>

<script>
	import { mapState } from 'vuex';
	export default {
		data() {
			return {
				avtar:require('@/static/images/headerImage.png'),
				show:true,
				keyword:'',
				navList:[{
					name: '全部',
					type:4,
				}, {
					name: '管理层',
					type:2,
				}, {
					name: '直推会员',
					type:3,
				}, {
					name: '店员',
					type:1,
				}],
				current: 0,
				info:'',
				total:0,
				status: 'loadmore', //加载前值为loadmore，加载中为loading，没有数据为nomore
				page: 1,
				list: [],
			};
		},
		computed:{
			...mapState({
				userinfo: state => state.userinfo
			}),
		},
		onLoad() {},
		onShow() {
			this.page=1
			this.getList()
		},
		methods:{
			// 列表
			getList() {
				var that = this
				if(that.page==1){
					that.$tips.showLoading('加载中')
				}else{
					that.status = 'loading'
				}
				var params = {
					level:that.navList[that.current].type,
					page:that.page,
					key: that.keyword,
				}
				that.$httpApi.userTeamIndex(params).then((res) => {
					if (res.code == 1) {
						that.info=res.data.info
						if (that.page == 1) {
							that.list = []
							that.$tips.hideLoading()
						}
						if (res.data.data.current_page == res.data.data.last_page) {
							that.status = 'nomore'
						} else {
							that.status = 'loadmore'
						}
						that.total=res.data.data.total
						that.list = that.list.concat(res.data.data.data)
					}
				})
			},
			// 搜索
			searchBtn(){
				this.page=1
				this.getList()
			},
			// nav
			navChange(index){
				this.current=index
				this.page=1
				this.getList()
			},
			// 查看详情
			detailsBtn(val){
				uni.navigateTo({
					url:'/pages/shop/team_details?id='+val
				})
			},
		}
	}
</script>

<style lang="less">
	.team{
		width: 100%;
		.team_top{
			position: fixed;
			z-index: 10;
			width: 100%;
			background: #fff;
			border-bottom: 2rpx solid #f7f8fa;
			.input{
				width: 100%;
				padding: 12rpx 32rpx;
			}
			.nav{
				width: 100%;
				height: 88rpx;
			}
		}
		.num_list{
			width: 100%;
			padding: 24rpx 0;
			background: #fff;
			display: flex;
			justify-content: space-between;
			.txt{
				flex: 1;
				// width: 100%;
				border-left: 2rpx solid #f7f8fa;
				text{
					display: block;
					width: 100%;
					text-align: center;
				}
				.t_num{
					font-size: 32rpx;
					font-family: OPPOSans-Bold, OPPOSans;
					font-weight: bold;
					color: #222222;
				}
				.t_tip{
					padding-top: 8rpx;
					font-size: 24rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #999999;
				}
			}
		}
		.list{
			width: 100%;
			margin-top: 24rpx;
			padding: 0 32rpx;
			background: #fff;
			.list_top{
				width: 100%;
				height: 110rpx;
				border-bottom: 2rpx solid #f7f8fa;
				display: flex;
				align-items: center;
				justify-content: space-between;
				.left{
					display: flex;
					align-items: center;
					image{
						display: block;
						width: 60rpx;
						height: 60rpx;
						border-radius: 50%;
					}
					text{
						padding-right: 10rpx;
						padding-left: 10rpx;
						font-size: 28rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #333333;
					}
					.left_tip{
						color: #FF6230;
					}
				}
				.right{
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #666666;
				}
			}
			.text{
				width: 100%;
				padding-top: 20rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				.left{
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #999999;
				}
				.right{
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #222222;
				}
			}
			.btn{
				width: 100%;
				padding: 32rpx 0;
				display: flex;
				justify-content: flex-end;
				text{
					display: block;
					padding: 0 30rpx;
					height: 68rpx;
					line-height: 64rpx;
					border-radius: 34rpx;
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #999;
					border: 2rpx solid #EBEBEB;
				}
			}
		}
	}
</style>
